Accord Software, Inc.

tutorial16/matrix.c




/* 
 * Accord Software, Inc.
 *               
 * Tutorial 16 - CIDL file.
 *
 * typedefs
 */
#include "matrix.h"

static int print();

MATRIX
addmatrix(a, b)
	Mp a;
	Mp b;
{
	static MATRIX retval;
	Mp sum = &retval;
	int x;
	int y;

	memset(&retval, 0, sizeof(struct matrix));

	/* 
	 * print out matricies a and b
	 */

	print("a", a);
	print("b", b);

	/* 
	 * add matrices a and b, put the result in sum
	 */

	for (y = 0; y < Y; y++) {
		for (x = 0; x < X; x++) {
			elem(sum) = elem(a) + elem(b);
		}
	}

	return retval;
}

/*
 * print out the matrix
 */

static int
print(s, a)
	char *s;
	Mp a;
{
	int x;
	int y;

	printf("matrix %s\n", s);
	for (y = 0; y < Y; y++) {
		printf("{ ");
		for (x = 0; x < X; x++) {
			printf("%d ", elem(a));
		}
		printf("}\n");
	}
}

int
matrixname(name)
	 MatrixName *name;
{
	int x;
	int y;

	print(name->name, &name->data);
	return 1;
}

[ Home | Tutorials | main.c | matrix.h ]
E-Mail:webmaster@accord.com
[P-057] Updated March 14, 1996
Copyright © 1993-1996 Accord Software, Inc. All rights reserved.